﻿
var statViewModel = new function () {
    this.Year = ko.observable(statData.FilterOption);
    this.ChartTypeOptions = ko.observableArray([{ ID: "Bar", ItemName: "Dạng thanh" }, { ID: "Line", ItemName: "Dòng" }, { ID: "Pie", ItemName: "Hình tròn"}]);
    this.ChartType = ko.observable(statData.ChartType);
    this.StatisticType = ko.observable(statData.StatisticType);
    this.SearchButton = function () {
        RedirectLink();
    };

    // PageSize/ PageCurrent keypress enter
    this.RunSomethingKey = function (viewModel, event) {
        if (event.keyCode == 13) {
            this.RunSomething(viewModel, event);
        }
        return true;
    }
    this.RunSomething = function (viewModel, event) {
        RedirectLink();
    }

    function RedirectLink() {
        var key = $('#q').val();

        if (key != undefined && key != null && key != '') {
            // Partial UI loading
            var link = "/LeadStatistic";
            if (statViewModel.StatisticType() == "Status")
                link += "/Statuses";
            else if (statViewModel.StatisticType() == "Source")
                link += "/Sources";
            else if (statViewModel.StatisticType() == "User")
                link += "/Users";

            link += "?chartType=" + statViewModel.ChartType() + "&filterType=year&filterOptions=" + key;

            window.location = link;
        }
        else {
            return false;
        }
    }
};

ko.applyBindings(statViewModel, document.getElementById("statSearchBox"));

function openPopupNoSearch() {
    closePopup();
    $('#fancybox-overlay').show();
    $('#popupNoSearch').showPopup({
        width: 400
    });
}

function openProcess() {
    $.fancybox($('#popup-process'), {
        padding: 0,
        closeBtn: false,
        helpers: {
            overlay: {
                opacity: 0.6,
                css: {
                    'background-color': '#11619D'
                }
            }
        },
        beforeClose: function () {
            return false;
        }
    });
    $('.fancybox-skin').show();
    $('#fancybox-overlay').show();
}

function ClosePopupSearch() 
{
    $('#popupNoSearch').hide();
    $('#fancybox-overlay').hide();
    $(".fancybox-wrap").hide();
}